{
  "name": "Case 58: Equipment Maintenance Predictor",
  "nodes": [
    {
      "parameters": {
        "pollTimes": {
          "item": [
            {
              "mode": "everyMinute"
            }
          ]
        },
        "triggerOn": "specificFolder",
        "folderToWatch": {
          "__rl": true,
          "value": "1ELj0WguhLszHMQtI61AsLVhrF_w_o4Os",
          "mode": "list",
          "cachedResultName": "Case 58 - Equipment Maintenance Folder",
          "cachedResultUrl": "https://drive.google.com/drive/folders/1ELj0WguhLszHMQtI61AsLVhrF_w_o4Os"
        },
        "event": "fileCreated",
        "options": {}
      },
      "id": "6ff7cea3-2758-4d4f-a9fe-8083284f9ee2",
      "name": "Monitor Inspection Reports Folder",
      "type": "n8n-nodes-base.googleDriveTrigger",
      "typeVersion": 1,
      "position": [
        -1056,
        -64
      ],
      "credentials": {
        "googleDriveOAuth2Api": {
          "id": "Cf6MNES8JrQntp3r",
          "name": "Google Drive account"
        }
      }
    },
    {
      "parameters": {
        "operation": "download",
        "fileId": {
          "__rl": true,
          "value": "={{ $json.id }}",
          "mode": "id"
        },
        "options": {}
      },
      "id": "de598b41-acd9-4164-b70d-dcdccf3b83f1",
      "name": "Download Inspection Report",
      "type": "n8n-nodes-base.googleDrive",
      "typeVersion": 3,
      "position": [
        -880,
        -64
      ],
      "credentials": {
        "googleDriveOAuth2Api": {
          "id": "Cf6MNES8JrQntp3r",
          "name": "Google Drive account"
        }
      }
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.cloud.llamaindex.ai/api/v1/parsing/upload",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "Bearer llx-7BWYrvPwfUhgdXbZMtaNCsr2O0h7JH4dkHjHisxcvq46bkIj"
            }
          ]
        },
        "sendBody": true,
        "contentType": "multipart-form-data",
        "bodyParameters": {
          "parameters": [
            {
              "parameterType": "formBinaryData",
              "name": "file",
              "inputDataFieldName": "data"
            }
          ]
        },
        "options": {}
      },
      "id": "91b9edbe-0402-4d41-b0f9-198b3644190b",
      "name": "Upload to Parser",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.3,
      "position": [
        -688,
        -64
      ]
    },
    {
      "parameters": {
        "amount": 20
      },
      "id": "850bdf88-d0ce-40c8-b8a2-acd66933c2be",
      "name": "Wait for Parsing",
      "type": "n8n-nodes-base.wait",
      "typeVersion": 1.1,
      "position": [
        -496,
        -64
      ],
      "webhookId": "df1df504-de89-4b44-a08e-49100d2d4eda"
    },
    {
      "parameters": {
        "url": "=https://api.cloud.llamaindex.ai/api/v1/parsing/job/{{ $node[\"Upload to Parser\"].json[\"id\"] }}",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "Bearer llx-7BWYrvPwfUhgdXbZMtaNCsr2O0h7JH4dkHjHisxcvq46bkIj"
            }
          ]
        },
        "options": {}
      },
      "id": "f4128686-4fb2-40bf-9422-e654c8e8563f",
      "name": "Check Parsing Status",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.3,
      "position": [
        -272,
        -64
      ]
    },
    {
      "parameters": {
        "rules": {
          "values": [
            {
              "conditions": {
                "conditions": [
                  {
                    "leftValue": "={{ $json.status }}",
                    "rightValue": "SUCCESS",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    }
                  }
                ]
              },
              "renameOutput": true,
              "outputKey": "SUCCESS"
            },
            {
              "conditions": {
                "conditions": [
                  {
                    "leftValue": "={{ $json.status }}",
                    "rightValue": "PENDING",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    }
                  }
                ]
              },
              "renameOutput": true,
              "outputKey": "PENDING"
            }
          ]
        },
        "options": {}
      },
      "id": "a1baee55-4581-4304-8178-3c2803cf294e",
      "name": "Route Based on Status",
      "type": "n8n-nodes-base.switch",
      "typeVersion": 3.3,
      "position": [
        -48,
        -64
      ]
    },
    {
      "parameters": {
        "url": "=https://api.cloud.llamaindex.ai/api/v1/parsing/job/{{ $node[\"Upload to Parser\"].json[\"id\"] }}/result/markdown",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "Bearer llx-7BWYrvPwfUhgdXbZMtaNCsr2O0h7JH4dkHjHisxcvq46bkIj"
            }
          ]
        },
        "options": {}
      },
      "id": "9f76f0bb-dac2-469d-b52c-0e2a27f039d3",
      "name": "Extract Parsed Content",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.3,
      "position": [
        160,
        -160
      ]
    },
    {
      "parameters": {
        "text": "={{ $json.markdown }}",
        "attributes": {
          "attributes": [
            {
              "name": "Asset_ID",
              "description": "Equipment asset ID or serial number"
            },
            {
              "name": "Equipment_Type",
              "description": "Type of equipment (e.g., Compressor, Pump, Motor, Generator)"
            },
            {
              "name": "Location",
              "description": "Physical location or facility name"
            },
            {
              "name": "Inspection_Date",
              "description": "Date of inspection"
            },
            {
              "name": "Runtime_Hours",
              "description": "Total operating hours or runtime"
            },
            {
              "name": "Vibration_Level_mm_s",
              "description": "Vibration reading in mm/s"
            },
            {
              "name": "Temperature_Celsius",
              "description": "Operating temperature in Celsius"
            },
            {
              "name": "Oil_Condition",
              "description": "Oil analysis result or condition (Good/Fair/Poor)"
            },
            {
              "name": "Noise_Level_dB",
              "description": "Noise level in decibels"
            },
            {
              "name": "Visual_Condition",
              "description": "Visual inspection notes (rust, leaks, cracks, wear)"
            },
            {
              "name": "Last_Maintenance_Date",
              "description": "Date of last maintenance or service"
            },
            {
              "name": "Inspector_Notes",
              "description": "Any additional observations or concerns"
            }
          ]
        },
        "options": {}
      },
      "id": "72dc4784-ec09-4e80-9502-4078265cfd3b",
      "name": "AI Data Extractor",
      "type": "@n8n/n8n-nodes-langchain.informationExtractor",
      "typeVersion": 1.2,
      "position": [
        336,
        -160
      ]
    },
    {
      "parameters": {
        "jsCode": "const inspectionData = $input.first().json.output;\n\n// ROBUST NUMBER EXTRACTION\nconst extractNumber = (str) => {\n  if (!str) return 0;\n  const cleaned = str.toString().replace(/[^\\d.-]/g, '');\n  const num = parseFloat(cleaned);\n  return isNaN(num) ? 0 : num;\n};\n\n// EMBEDDED EQUIPMENT DATABASE WITH FAILURE THRESHOLDS\nconst equipmentDatabase = {\n  \"Compressor\": {\n    max_vibration: 7.1,\n    max_temperature: 85,\n    max_noise: 85,\n    maintenance_interval_hours: 8000,\n    critical_runtime_hours: 15000,\n    replacement_cost: 450000,\n    downtime_cost_per_hour: 25000,\n    common_failures: [\"bearing failure\", \"seal leak\", \"motor burnout\"]\n  },\n  \"Centrifugal Pump\": {\n    max_vibration: 4.5,\n    max_temperature: 70,\n    max_noise: 75,\n    maintenance_interval_hours: 6000,\n    critical_runtime_hours: 12000,\n    replacement_cost: 180000,\n    downtime_cost_per_hour: 15000,\n    common_failures: [\"impeller wear\", \"seal failure\", \"cavitation\"]\n  },\n  \"Electric Motor\": {\n    max_vibration: 3.5,\n    max_temperature: 80,\n    max_noise: 80,\n    maintenance_interval_hours: 10000,\n    critical_runtime_hours: 20000,\n    replacement_cost: 220000,\n    downtime_cost_per_hour: 18000,\n    common_failures: [\"winding failure\", \"bearing damage\", \"overheating\"]\n  },\n  \"Generator\": {\n    max_vibration: 5.0,\n    max_temperature: 90,\n    max_noise: 90,\n    maintenance_interval_hours: 5000,\n    critical_runtime_hours: 10000,\n    replacement_cost: 850000,\n    downtime_cost_per_hour: 50000,\n    common_failures: [\"alternator failure\", \"fuel system issue\", \"cooling system failure\"]\n  },\n  \"Hydraulic Press\": {\n    max_vibration: 6.0,\n    max_temperature: 65,\n    max_noise: 80,\n    maintenance_interval_hours: 4000,\n    critical_runtime_hours: 8000,\n    replacement_cost: 320000,\n    downtime_cost_per_hour: 22000,\n    common_failures: [\"hydraulic leak\", \"cylinder failure\", \"valve malfunction\"]\n  },\n  \"Conveyor Belt System\": {\n    max_vibration: 2.5,\n    max_temperature: 50,\n    max_noise: 70,\n    maintenance_interval_hours: 3000,\n    critical_runtime_hours: 6000,\n    replacement_cost: 125000,\n    downtime_cost_per_hour: 12000,\n    common_failures: [\"belt wear\", \"roller bearing failure\", \"motor failure\"]\n  }\n};\n\n// OIL CONDITION SCORING\nconst oilConditionScores = {\n  \"Good\": 0,\n  \"Excellent\": 0,\n  \"Fair\": 1,\n  \"Satisfactory\": 1,\n  \"Poor\": 3,\n  \"Bad\": 3,\n  \"Critical\": 5,\n  \"Contaminated\": 4\n};\n\n// VISUAL CONDITION KEYWORDS\nconst criticalVisualKeywords = [\"crack\", \"leak\", \"rust\", \"corrosion\", \"excessive wear\", \"damage\", \"broken\"];\n\n// Extract inspection data\nconst assetID = inspectionData.Asset_ID || 'UNKNOWN';\nconst equipmentType = inspectionData.Equipment_Type || 'Unknown';\nconst location = inspectionData.Location || 'Unknown';\nconst inspectionDate = inspectionData.Inspection_Date || new Date().toISOString().split('T')[0];\nconst runtimeHours = extractNumber(inspectionData.Runtime_Hours);\nconst vibrationLevel = extractNumber(inspectionData.Vibration_Level_mm_s);\nconst temperature = extractNumber(inspectionData.Temperature_Celsius);\nconst oilCondition = (inspectionData.Oil_Condition || 'Unknown').trim();\nconst noiseLevel = extractNumber(inspectionData.Noise_Level_dB);\nconst visualCondition = (inspectionData.Visual_Condition || '').toLowerCase();\nconst lastMaintenanceDate = inspectionData.Last_Maintenance_Date || 'Not recorded';\nconst inspectorNotes = inspectionData.Inspector_Notes || 'None';\n\n// Get equipment specifications\nconst equipmentSpecs = equipmentDatabase[equipmentType] || {\n  max_vibration: 5.0,\n  max_temperature: 75,\n  max_noise: 80,\n  maintenance_interval_hours: 5000,\n  critical_runtime_hours: 10000,\n  replacement_cost: 250000,\n  downtime_cost_per_hour: 20000,\n  common_failures: [\"general wear\"]\n};\n\n// INTELLIGENCE 1: Calculate days since last maintenance\nlet daysSinceLastMaintenance = 'Unknown';\nlet maintenanceOverdue = false;\nif (lastMaintenanceDate !== 'Not recorded') {\n  try {\n    const lastMaintDate = new Date(lastMaintenanceDate);\n    const inspectDate = new Date(inspectionDate);\n    daysSinceLastMaintenance = Math.floor((inspectDate - lastMaintDate) / (1000 * 60 * 60 * 24));\n    \n    const expectedMaintenanceInterval = Math.floor(equipmentSpecs.maintenance_interval_hours / 24);\n    maintenanceOverdue = daysSinceLastMaintenance > expectedMaintenanceInterval;\n  } catch (e) {\n    daysSinceLastMaintenance = 'Invalid date';\n  }\n}\n\n// INTELLIGENCE 2: Calculate failure risk score (0-100)\nlet failureRiskScore = 0;\nconst riskFactors = [];\n\n// Vibration analysis\nif (vibrationLevel > equipmentSpecs.max_vibration) {\n  const vibrationExcess = ((vibrationLevel - equipmentSpecs.max_vibration) / equipmentSpecs.max_vibration * 100);\n  failureRiskScore += Math.min(vibrationExcess, 25);\n  riskFactors.push(`Vibration ${vibrationExcess.toFixed(0)}% above threshold`);\n}\n\n// Temperature analysis\nif (temperature > equipmentSpecs.max_temperature) {\n  const tempExcess = ((temperature - equipmentSpecs.max_temperature) / equipmentSpecs.max_temperature * 100);\n  failureRiskScore += Math.min(tempExcess, 20);\n  riskFactors.push(`Temperature ${tempExcess.toFixed(0)}% above normal`);\n}\n\n// Noise analysis\nif (noiseLevel > equipmentSpecs.max_noise) {\n  const noiseExcess = ((noiseLevel - equipmentSpecs.max_noise) / equipmentSpecs.max_noise * 100);\n  failureRiskScore += Math.min(noiseExcess, 15);\n  riskFactors.push(`Excessive noise detected`);\n}\n\n// Oil condition analysis\nconst oilScore = oilConditionScores[oilCondition] || 0;\nfailureRiskScore += oilScore * 5;\nif (oilScore >= 3) {\n  riskFactors.push(`Oil condition: ${oilCondition}`);\n}\n\n// Runtime analysis\nconst runtimePercent = (runtimeHours / equipmentSpecs.critical_runtime_hours) * 100;\nif (runtimePercent > 80) {\n  failureRiskScore += (runtimePercent - 80);\n  riskFactors.push(`Runtime at ${runtimePercent.toFixed(0)}% of critical threshold`);\n}\n\n// Visual inspection analysis\nconst hasVisualIssues = criticalVisualKeywords.some(keyword => visualCondition.includes(keyword));\nif (hasVisualIssues) {\n  failureRiskScore += 15;\n  riskFactors.push('Critical visual defects detected');\n}\n\n// Maintenance overdue penalty\nif (maintenanceOverdue) {\n  failureRiskScore += 10;\n  riskFactors.push('Maintenance overdue');\n}\n\nfailureRiskScore = Math.min(Math.round(failureRiskScore), 100);\n\n// INTELLIGENCE 3: Determine health status and priority\nlet healthStatus = 'Good';\nlet maintenancePriority = 'Low';\nlet maintenanceUrgency = 'Routine';\n\nif (failureRiskScore >= 70) {\n  healthStatus = 'Critical';\n  maintenancePriority = 'Emergency';\n  maintenanceUrgency = 'Immediate (0-3 days)';\n} else if (failureRiskScore >= 50) {\n  healthStatus = 'Poor';\n  maintenancePriority = 'High';\n  maintenanceUrgency = 'Urgent (1-2 weeks)';\n} else if (failureRiskScore >= 30) {\n  healthStatus = 'Fair';\n  maintenancePriority = 'Medium';\n  maintenanceUrgency = 'Scheduled (2-4 weeks)';\n} else {\n  healthStatus = 'Good';\n  maintenancePriority = 'Low';\n  maintenanceUrgency = 'Routine (next service cycle)';\n}\n\n// INTELLIGENCE 4: Calculate failure probability\nconst failureProbability = Math.min((failureRiskScore / 100 * 80) + (runtimePercent > 100 ? 20 : 0), 95);\n\n// INTELLIGENCE 5: Cost analysis\nconst estimatedDowntimeDays = failureRiskScore >= 70 ? 5 : failureRiskScore >= 50 ? 3 : 1;\nconst breakdownCost = equipmentSpecs.replacement_cost + (equipmentSpecs.downtime_cost_per_hour * estimatedDowntimeDays * 8);\nconst preventiveCost = equipmentSpecs.replacement_cost * 0.15;\nconst costAvoidance = breakdownCost - preventiveCost;\n\n// INTELLIGENCE 6: Generate recommendations\nconst recommendations = [];\n\nif (failureRiskScore >= 70) {\n  recommendations.push('STOP OPERATIONS - Schedule immediate shutdown and inspection');\n  recommendations.push('Arrange emergency maintenance crew');\n  recommendations.push('Prepare backup equipment if available');\n}\n\nif (vibrationLevel > equipmentSpecs.max_vibration) {\n  recommendations.push('Check bearing alignment and lubrication');\n  recommendations.push('Inspect for loose mountings or imbalance');\n}\n\nif (temperature > equipmentSpecs.max_temperature) {\n  recommendations.push('Verify cooling system operation');\n  recommendations.push('Check for excessive load or friction');\n}\n\nif (oilScore >= 3) {\n  recommendations.push('Perform oil change immediately');\n  recommendations.push('Check for contamination sources');\n}\n\nif (hasVisualIssues) {\n  recommendations.push('Conduct detailed visual inspection');\n  recommendations.push('Document defects with photos');\n}\n\nif (runtimePercent > 80) {\n  recommendations.push('Plan major overhaul or replacement');\n  recommendations.push('Review equipment lifecycle and ROI');\n}\n\nif (maintenanceOverdue) {\n  recommendations.push('Execute overdue preventive maintenance');\n}\n\nif (recommendations.length === 0) {\n  recommendations.push('Continue normal monitoring schedule');\n  recommendations.push('Document current baseline readings');\n}\n\n// INTELLIGENCE 7: Parts procurement suggestions\nconst partsToProcure = [];\nif (failureRiskScore >= 50) {\n  equipmentSpecs.common_failures.forEach(failure => {\n    partsToProcure.push(failure.split(' ')[0] + ' replacement kit');\n  });\n}\n\nreturn {\n  json: {\n    Asset_ID: assetID,\n    Equipment_Type: equipmentType,\n    Location: location,\n    Inspection_Date: inspectionDate,\n    Runtime_Hours: runtimeHours.toFixed(0),\n    Days_Since_Last_Maintenance: String(daysSinceLastMaintenance),\n    Vibration_Level_mm_s: vibrationLevel.toFixed(2),\n    Vibration_Status: vibrationLevel > equipmentSpecs.max_vibration ? `⚠️ HIGH (>${equipmentSpecs.max_vibration})` : '✓ Normal',\n    Temperature_Celsius: temperature.toFixed(1),\n    Temperature_Status: temperature > equipmentSpecs.max_temperature ? `⚠️ HIGH (>${equipmentSpecs.max_temperature})` : '✓ Normal',\n    Oil_Condition: oilCondition,\n    Noise_Level_dB: noiseLevel.toFixed(0),\n    Visual_Issues_Detected: hasVisualIssues ? 'Yes - Critical defects found' : 'No',\n    Health_Status: healthStatus,\n    Failure_Risk_Score: `${failureRiskScore}/100`,\n    Failure_Probability_Percent: failureProbability.toFixed(1) + '%',\n    Risk_Factors: riskFactors.join('; ') || 'None',\n    Maintenance_Priority: maintenancePriority,\n    Maintenance_Urgency: maintenanceUrgency,\n    Estimated_Breakdown_Cost_INR: breakdownCost.toFixed(0),\n    Preventive_Maintenance_Cost_INR: preventiveCost.toFixed(0),\n    Cost_Avoidance_INR: costAvoidance.toFixed(0),\n    Recommendations: recommendations.join('; '),\n    Parts_to_Procure: partsToProcure.join(', ') || 'None at this time',\n    Inspector_Notes: inspectorNotes,\n    Processing_Timestamp: new Date().toISOString()\n  }\n};"
      },
      "id": "07e2e6f8-29da-4b8a-842d-6f5bceabf722",
      "name": "Maintenance Prediction Analyzer",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        592,
        -160
      ]
    },
    {
      "parameters": {
        "operation": "append",
        "documentId": {
          "__rl": true,
          "value": "1gJ4NeeeI6kSYX-3fn-iY2uFPSmYNBMrt8Zu60atp_ec",
          "mode": "list",
          "cachedResultName": "Case 58 Equipment Maintenance Log",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1gJ4NeeeI6kSYX-3fn-iY2uFPSmYNBMrt8Zu60atp_ec/edit?usp=drivesdk"
        },
        "sheetName": {
          "__rl": true,
          "value": "gid=0",
          "mode": "list",
          "cachedResultName": "Sheet1",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1gJ4NeeeI6kSYX-3fn-iY2uFPSmYNBMrt8Zu60atp_ec/edit#gid=0"
        },
        "columns": {
          "mappingMode": "autoMapInputData",
          "value": {},
          "matchingColumns": [],
          "schema": [
            {
              "id": "Asset_ID",
              "displayName": "Asset_ID",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Equipment_Type",
              "displayName": "Equipment_Type",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Location",
              "displayName": "Location",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Inspection_Date",
              "displayName": "Inspection_Date",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Runtime_Hours",
              "displayName": "Runtime_Hours",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Days_Since_Last_Maintenance",
              "displayName": "Days_Since_Last_Maintenance",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Vibration_Level_mm_s",
              "displayName": "Vibration_Level_mm_s",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Vibration_Status",
              "displayName": "Vibration_Status",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Temperature_Celsius",
              "displayName": "Temperature_Celsius",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Temperature_Status",
              "displayName": "Temperature_Status",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Oil_Condition",
              "displayName": "Oil_Condition",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Noise_Level_dB",
              "displayName": "Noise_Level_dB",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Visual_Issues_Detected",
              "displayName": "Visual_Issues_Detected",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Health_Status",
              "displayName": "Health_Status",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Failure_Risk_Score",
              "displayName": "Failure_Risk_Score",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Failure_Probability_Percent",
              "displayName": "Failure_Probability_Percent",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Risk_Factors",
              "displayName": "Risk_Factors",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Maintenance_Priority",
              "displayName": "Maintenance_Priority",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Maintenance_Urgency",
              "displayName": "Maintenance_Urgency",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Estimated_Breakdown_Cost_INR",
              "displayName": "Estimated_Breakdown_Cost_INR",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Preventive_Maintenance_Cost_INR",
              "displayName": "Preventive_Maintenance_Cost_INR",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Cost_Avoidance_INR",
              "displayName": "Cost_Avoidance_INR",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Recommendations",
              "displayName": "Recommendations",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Parts_to_Procure",
              "displayName": "Parts_to_Procure",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Inspector_Notes",
              "displayName": "Inspector_Notes",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Processing_Timestamp",
              "displayName": "Processing_Timestamp",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            }
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {}
      },
      "id": "009468a8-efb9-45ca-9cf4-25ee27da9ae9",
      "name": "Log to Google Sheets",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.7,
      "position": [
        768,
        -160
      ],
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "LOs2dbk9lby0NfDM",
          "name": "Google Sheets account"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "const data = $input.first().json;\n\nconst assetID = data.Asset_ID || 'Unknown';\nconst equipmentType = data.Equipment_Type || 'Equipment';\nconst healthStatus = data.Health_Status || 'Unknown';\nconst priority = data.Maintenance_Priority || 'Unknown';\nconst riskScore = data.Failure_Risk_Score || '0/100';\n\nconst isCritical = priority === 'Emergency';\nconst isHighPriority = priority === 'High';\n\nconst emailSubject = isCritical \n  ? `🚨 CRITICAL: ${equipmentType} ${assetID} Failure Imminent` \n  : isHighPriority\n  ? `⚠️ HIGH PRIORITY: ${equipmentType} ${assetID} Maintenance Required`\n  : `Maintenance Prediction Report - ${equipmentType} ${assetID}`;\n\nconst emailBody = `Dear Maintenance Team,\n\nAn equipment inspection report has been processed with predictive maintenance analysis.\n\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n🔧 EQUIPMENT DETAILS\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\nAsset ID: ${data.Asset_ID}\nEquipment Type: ${data.Equipment_Type}\nLocation: ${data.Location}\nInspection Date: ${data.Inspection_Date}\nRuntime Hours: ${data.Runtime_Hours}\nDays Since Last Maintenance: ${data.Days_Since_Last_Maintenance}\n\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n📊 CONDITION ASSESSMENT\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\nVibration: ${data.Vibration_Level_mm_s} mm/s - ${data.Vibration_Status}\nTemperature: ${data.Temperature_Celsius}°C - ${data.Temperature_Status}\nOil Condition: ${data.Oil_Condition}\nNoise Level: ${data.Noise_Level_dB} dB\nVisual Issues: ${data.Visual_Issues_Detected}\n\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n⚠️ FAILURE RISK ANALYSIS\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\nHealth Status: ${healthStatus}\nFailure Risk Score: ${riskScore}\nFailure Probability: ${data.Failure_Probability_Percent}\nRisk Factors: ${data.Risk_Factors}\n\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n🎯 MAINTENANCE PRIORITY\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\nPriority Level: ${priority}\nMaintenance Urgency: ${data.Maintenance_Urgency}\n\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n💰 COST ANALYSIS\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\nEstimated Breakdown Cost: ₹${data.Estimated_Breakdown_Cost_INR}\nPreventive Maintenance Cost: ₹${data.Preventive_Maintenance_Cost_INR}\nPotential Cost Avoidance: ₹${data.Cost_Avoidance_INR}\n\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n✅ RECOMMENDED ACTIONS\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n${data.Recommendations}\n\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n🔩 PARTS PROCUREMENT\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n${data.Parts_to_Procure}\n\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n📝 INSPECTOR NOTES\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n${data.Inspector_Notes}\n\n${\n  isCritical \n    ? `🚨 CRITICAL ALERT: This equipment requires IMMEDIATE attention to prevent catastrophic failure and production shutdown. Execute emergency maintenance protocol.` \n    : isHighPriority \n    ? `⚠️ HIGH PRIORITY: Schedule maintenance within the recommended timeframe to avoid unplanned downtime.` \n    : `✓ ROUTINE: Equipment is operating within acceptable parameters. Continue normal monitoring.`\n}\n\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\nProcessed: ${data.Processing_Timestamp}\n\nThis is an automated predictive analysis from the Equipment Maintenance System.\nFor detailed metrics, refer to the Maintenance Predictions dashboard.\n\nBest regards,\nPredictive Maintenance System`;\n\nreturn {\n  json: {\n    email_subject: emailSubject,\n    email_body: emailBody,\n    recipient_email: 'maintenance.manager@company.com',\n    cc_email: isCritical ? 'operations.head@company.com, plant.manager@company.com' : 'operations.head@company.com',\n    asset_id: assetID,\n    priority: priority,\n    risk_score: riskScore\n  }\n};"
      },
      "id": "b40e41ce-7d12-416c-a8b0-b24b605f6a31",
      "name": "Generate Email Summary",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        976,
        -160
      ]
    },
    {
      "parameters": {
        "sendTo": "={{ $json.recipient_email }}",
        "subject": "={{ $json.email_subject }}",
        "emailType": "text",
        "message": "={{ $json.email_body }}",
        "options": {}
      },
      "id": "ac1a76ef-6678-4c62-a424-ba4b0b854874",
      "name": "Send Email via Gmail",
      "type": "n8n-nodes-base.gmail",
      "typeVersion": 2.1,
      "position": [
        1168,
        -160
      ],
      "webhookId": "1d35cae5-0fe5-4d41-9d6f-92f2ca90ff0f",
      "credentials": {
        "gmailOAuth2": {
          "id": "cyqCGWcggZNMcSOv",
          "name": "Gmail account"
        }
      }
    },
    {
      "parameters": {
        "model": {
          "__rl": true,
          "value": "gpt-4o-mini",
          "mode": "list"
        },
        "builtInTools": {},
        "options": {}
      },
      "id": "0e1d57b0-aaee-47ff-b7af-cec4571bdd68",
      "name": "OpenAI GPT-4o Mini",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1.3,
      "position": [
        336,
        48
      ],
      "credentials": {
        "openAiApi": {
          "id": "ICwxUBbatsF2sDvy",
          "name": "OpenAi account"
        }
      }
    }
  ],
  "pinData": {},
  "connections": {
    "Monitor Inspection Reports Folder": {
      "main": [
        [
          {
            "node": "Download Inspection Report",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Download Inspection Report": {
      "main": [
        [
          {
            "node": "Upload to Parser",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Upload to Parser": {
      "main": [
        [
          {
            "node": "Wait for Parsing",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait for Parsing": {
      "main": [
        [
          {
            "node": "Check Parsing Status",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check Parsing Status": {
      "main": [
        [
          {
            "node": "Route Based on Status",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Route Based on Status": {
      "main": [
        [
          {
            "node": "Extract Parsed Content",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Wait for Parsing",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract Parsed Content": {
      "main": [
        [
          {
            "node": "AI Data Extractor",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Data Extractor": {
      "main": [
        [
          {
            "node": "Maintenance Prediction Analyzer",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Maintenance Prediction Analyzer": {
      "main": [
        [
          {
            "node": "Log to Google Sheets",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Log to Google Sheets": {
      "main": [
        [
          {
            "node": "Generate Email Summary",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Generate Email Summary": {
      "main": [
        [
          {
            "node": "Send Email via Gmail",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI GPT-4o Mini": {
      "ai_languageModel": [
        [
          {
            "node": "AI Data Extractor",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "c3519898-6688-414d-b1a4-242898693946",
  "meta": {
    "templateCredsSetupCompleted": true,
    "instanceId": "3a43da28588548e21903e71cf1dc3ddd65c24bf0c62e7e4b77542ffe87ad79c6"
  },
  "id": "X9gQKBR57tquo6uW",
  "tags": []
}